#H0:My average daily screen time is less than or equal 2. #Ha:My average daily screen time exceeds the 2 hours recommended time.
#Experts say adults should limit screen time to 2 hours. In this case, i will be using recommended limit time of 2 hours.
\(H0: p = 2.0\) \(Ha:p > 2.0\)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
library(plotly)
##
## Attaching package: 'plotly'
##
## The following object is masked from 'package:ggplot2':
##
## last_plot
##
## The following object is masked from 'package:stats':
##
## filter
##
## The following object is masked from 'package:graphics':
##
## layout
library(readxl)
ScreenTime <- read_excel("/Users/AhmedFarah/Documents/Data Science/ScreenTime.xlsx")
graph1 <- ggplot(ScreenTime, aes(x=Day, y=ScreenTime, color= Day))+geom_line() + geom_point()+ labs(title = "Daily Screen Time Over Two Weeks", x="Day", y="Screen Time (hours)")
ggplotly(graph1)
#Each point on the line shows the screen time for a specific day
#Histogram of screen time disribution
graph2 <- ggplot(ScreenTime, aes(x=ScreenTime))+geom_histogram(binwidth = 0.5, fill="skyblue", color="black")+labs(title = "Distribution of Daily Scrreen Time", x="Screen Time (hours)", y="Frequency")
ggplotly(graph2)
#The histogram shows the disribution of daily screentime, with each bar representing the frequency of screen time within a certain range of hours.
#boxplot
graph3 <- ggplot(ScreenTime, aes(y = ScreenTime)) + geom_boxplot(fill="lightgreen", color="black")+ labs("Boxplot of Daily Screen Time", y="Screen Time (Hours)")
ggplotly(graph3)
#no outliers for the Screen time data. Screen time is between 2.5 - 6.5
One-sample t-test
t.test(ScreenTime$ScreenTime, mu=2, alternative = "greater")
##
## One Sample t-test
##
## data: ScreenTime$ScreenTime
## t = 6.1287, df = 14, p-value = 1.306e-05
## alternative hypothesis: true mean is greater than 2
## 95 percent confidence interval:
## 3.567748 Inf
## sample estimates:
## mean of x
## 4.2
#Two-sample t-test #H0:There is no significant difference between the average screen time on weekends and weekdays.
#HA: The average screen time on weekends differs from weekdays.
\(H0: weekends = weekdays\) \(Ha: weekends \ne weekdays\)
weekdays <- ScreenTime %>% filter(Day %in% c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday"))
weekends <- ScreenTime %>% filter(Day %in% c("Saturday", "Sunday"))
t.test(weekends$ScreenTime, weekdays$ScreenTime, alternative = "two.sided")
##
## Welch Two Sample t-test
##
## data: weekends$ScreenTime and weekdays$ScreenTime
## t = 2.1958, df = 6.1556, p-value = 0.06937
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.1613176 3.1613176
## sample estimates:
## mean of x mean of y
## 5.3 3.8
#With a p-value = 0.67 we fail to reject the null hypothesis. This proves that there is insuffienct evidence to support that average screen time on weekends differs significantly from weekdays.
#Simple Linear regression
linear <- lm(ScreenTime ~ Day, data=ScreenTime)
summary(linear)
##
## Call:
## lm(formula = ScreenTime ~ Day, data = ScreenTime)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.25000 -0.22500 0.03333 0.22500 1.25000
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 6.0000 0.4878 12.301 1.77e-06 ***
## DayMonday -2.5333 0.6297 -4.023 0.00382 **
## DaySaturday -1.6500 0.6898 -2.392 0.04372 *
## DaySunday 0.2500 0.6898 0.362 0.72643
## DayThursday -2.7500 0.6898 -3.987 0.00402 **
## DayTuesday -3.3000 0.6898 -4.784 0.00138 **
## DayWednesday -2.2500 0.6898 -3.262 0.01150 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6898 on 8 degrees of freedom
## Multiple R-squared: 0.8593, Adjusted R-squared: 0.7538
## F-statistic: 8.145 on 6 and 8 DF, p-value: 0.00463
#Summary
#The analysis of daily screen time over a two-week period revealed that the mean daily screen time was 4.2 hours, which exceeds the recommended 2-hour limit.
#Hypothesis testing showed that there was no significant difference between the average screen time on weekends and weekdays, indicating consistent screen usage patterns across the week.